package cn.steam.foo.ctrl;

import cn.steam.foo.api.UserApi;
import cn.steam.foo.model.UserVO;
import cn.steam.foo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author zhang jintao on 2022/05/11
 **/
@RestController
public class UserCtrl implements UserApi {

    @Autowired
    UserService userService;

    @Override
    public UserVO getById(@RequestParam Long id) {
        return userService.getById(id);
    }

    @Override
    public void delete(@RequestParam Long id) {
        userService.delete(id);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public String importUsers(@RequestParam Integer num) {
        String task = UUID.randomUUID().toString();
        userService.saveAll(task, num);
        return task;
    }

    @Override
    public Double getTask(String sn) {
        return userService.getTask(sn);
    }
}
